import random


def select_one_from_weight_map(weight_map, exclude=None):
    weight_sum_now = 0
    upper_list = []
    if exclude is None:
        exclude = {}
    for element, weight in weight_map.items():
        if element in exclude:
            continue
        weight_sum_now += weight
        upper_list.append({'element': element, 'weight_sum_now': weight_sum_now})
    rand_num = random.uniform(0, weight_sum_now)
    for item in upper_list:
        if rand_num <= item['weight_sum_now']:
            return item['element']
